home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / msh20.zip / MSHFILES.ZIP / STDDEFS.MSH < prev    next >
Text File  |  1992-03-26  |  15KB  |  511 lines

  1. |    file: STDDEF.MSH      Standard definitions for Mi-Shell
  2. |───────────────────────────────────────────────────────────
  3. |
  4. |              ┌─────────────────────────────────────────────┐
  5. |              │ utilities to get various parts of a pathname│
  6. |              └─────────────────────────────────────────────┘
  7. |
  8. ("."cutlast drop)basename!
  9. ("."cutlast swap drop)extension!
  10. |
  11. | the following definition tests if top is a substring of top+1
  12. |
  13. (swap dup 3 roll cutfirst drop = not )belong!
  14. |
  15. | Cut a pathname into its unit and the rest.
  16. |
  17. (dup ":"cutfirst dup
  18.  (3 roll drop swap":"&swap)
  19.  (drop 2 pick =
  20.   (false swap)
  21.   (false)
  22.   ifelse
  23.  )
  24.  ifelse
  25. )unit_and_name!
  26. |
  27. | Get the directory of a pathname. It is hard because of DOS's dumb syntax.
  28. | examples:  "a:x\y" -> "a:x", "a:x\" -> "a:x\.",   "a:" -> "a:.", etc...
  29. |
  30. (unit_and_name
  31.  dup"\\"cutlast
  32.  (dup(swap drop)
  33.      (drop drop "\\")
  34.      ifelse
  35.  )
  36.  (drop &".")
  37.  ifelse
  38.  &
  39. )directory!
  40. |
  41. | A simpler variant which gives the directory part of a pathname, so
  42. | that dirpart&filepart=initial pathname.
  43. | examples:  "a:x\y" -> "a:x\", "a:x\" -> "a:x\",   "a:" -> "a:", etc...
  44. |
  45. (dup "\\"endsby("."&)if
  46.  unit_and_name"\\"cutlast
  47.  ("\\"&)
  48.  (drop"")
  49.  ifelse
  50.  &
  51. )dirpart!
  52. |
  53. | Get the filename part of a pathname.
  54. |
  55. (unit_and_name swap drop
  56.  "\\"cutlast dup
  57.  (swap drop)
  58.  (drop)
  59.  ifelse
  60. )filepart!
  61. |
  62. | makename puts together a directory and a filename. The difficulty is
  63. | to add a '\' when necessary.
  64. |
  65. (2 pick swap cutlast (drop drop false)(match not)ifelse)endsby!
  66. |
  67. (swap
  68.  dup "\\" endsby
  69.  (dup ":" endsby
  70.   ("\\"&)ifnot
  71.  )
  72.  ifnot
  73.  swap &
  74. )makename!
  75. |
  76. |              ┌─────────────────────────────────┐
  77. |              │ various kind of loops on a panel│
  78. |              └─────────────────────────────────┘
  79. |
  80. | loop_panel: general loop operator. Assumes top is a piece of code and
  81. | executes it for each entry in the panel
  82. |
  83. ( action! current.pos oldpos! 0 current.pos!
  84.   (action current.pos 1+ dup current.pos! panel.nbfiles = not)()while
  85.   oldpos current.pos!
  86. )loop_panel!
  87. |
  88. | deselect: deselect all selected files.
  89. |
  90. ((current.selected(false current.selected!)if)loop_panel)deselect!
  91. |
  92. | foreachselected: supposes <Top> is a piece of code taking 1 argument,
  93. | and execute for each selected file that code with the selected
  94. | file as argument (uses current if no file was selected)
  95. |
  96. ( action! current.pos oldpos! 0 current.pos! false found!
  97.   (current.selected(true found! false current.selected! current.name action)if
  98.    current.pos 1+ dup current.pos! panel.nbfiles = not)()
  99.   while
  100.   oldpos current.pos!
  101.   found (current.name action)ifnot
  102. )foreachselected!
  103. |
  104. | foreachbase: same as foreachselected but use the basename as argument.
  105. |
  106. ( action! current.pos oldpos! 0 current.pos! false found!
  107.   (current.selected(true found! false current.selected! current.name basename
  108.    action)if current.pos 1+ dup current.pos! panel.nbfiles = not)()
  109.   while
  110.   oldpos current.pos!
  111.   found (current.name action)ifnot
  112. )foreachbase!
  113. |
  114. | selected_list: <Push> the list of selected files, catenated with blanks
  115. | as separators. If nothing was selected, <Push> current.
  116. |
  117. ( false (current.selected(current.name&" "&)if)loop_panel
  118.   dup (drop current.name)ifnot
  119. )selected_list!
  120. |
  121. | next: circular version of down to be used in circular searches
  122. |
  123. (current.pos 1+ dup current.pos! panel.nbfiles=(0 current.pos!)if)next!
  124. |
  125. | search: positions to the first file matching <Top>
  126. |
  127. ( current.name
  128.   (2 pick current.name match
  129.    (false)
  130.    (next dup current.name = not)
  131.    ifelse
  132.   )
  133.   ()
  134.   while
  135.   drop
  136. )search!
  137. |
  138. |              ┌──────────────────────┐
  139. |              │ updates of the panels│
  140. |              └──────────────────────┘
  141. |
  142. |  refresh refills the panel with the contents of the current directory
  143. |
  144. (cwd panel.pattern filepart makename panel.pattern!)refresh!
  145. |
  146. |  reread updates the current panel by rereading from disk (but doesn't
  147. |  change its directory to the current one: use refresh for that)
  148. |
  149. (panel.pattern panel.pattern!)reread!
  150. |
  151. | variants which deal with the next panel
  152. |
  153. ("panel.on_activate"@oa! ()panel.on_activate! next_panel
  154.  #prev_panel oa "panel.on_activate!"&#)in_next_panel!
  155. ((reread) in_next_panel)reread_next!
  156. ((panel.pattern directory)in_next_panel)next_dir!
  157. |
  158. |
  159. |              ┌──────────────────────┐
  160. |              │ variants of 'execute'│
  161. |              └──────────────────────┘
  162. |
  163. | execshow: show the command in a message window before executing it
  164. |
  165. (dup 600 swap"Executing..." swap flash execute)execshow!
  166. |
  167. | exec: usual variant: just reread after 'execute'
  168. |
  169. (execute reread)exec!
  170. |
  171. | with_magic: do something with `magic' swap enabled
  172. | with_nomagic: do something with magic off
  173. | with_magicnoxms: do something with swap to disk enabled but swap to xms disabled
  174. |
  175. (magic oldmagic!"*"magic! # oldmagic magic!)with_nomagic!
  176. (magic oldmagic!tmp_dir magic! # oldmagic magic!)with_magic!
  177. (magic oldmagic!"*"tmp_dir& magic! # oldmagic magic!)with_magicnoxms!
  178. |
  179. | confirm: ask confirmation before executing command
  180. |
  181. (act! dup ok(act)(drop)ifelse)confirm!
  182. |
  183. ((true)(false)3 roll nl&" %yes% %no%"&
  184. (false)"-1" 5 e_att e_att current_selected_att true false menu.install)
  185. my_ok!
  186. |
  187. | execsave: variant executed by Enter which saves the command on the circular
  188. | list of saved commands before execution
  189. |
  190. ( cmd dup cmdlist nl&swap&cmdlist! dup
  191.   " "cutfirst drop"."cutfirst drop"*"nl&swap&nl&"*"& dup magic_list match
  192.   ( drop(execute)with_magic)
  193.   ( nl"set"&match
  194.     ("="cutfirst dup(swap " " cutlast swap drop "$"swap& !)
  195.                     (drop execute)ifelse)
  196.     (execute)ifelse
  197.   )ifelse 
  198.   cmd.clear refresh
  199. )execsave!
  200. |
  201. | below is part of the code for Enter.
  202. |
  203. ( current.isdir
  204.   ( current.name cwd! refresh)
  205.   ( "extension_" current.name extension&#)
  206.   ifelse
  207. )cur_action!
  208. |
  209. ("cur_action"panel.type&#)act_on_cur!
  210. |
  211. (current.isdir
  212.  (current.name cwd! refresh)
  213.  ("extension2_" current.name extension&#)
  214.  ifelse
  215. )act2_on_cur!
  216. |
  217. |              ┌───────────────────────────────┐
  218. |              │ now, the actions on the panels│
  219. |              └───────────────────────────────┘
  220. |
  221. | wide_narrow: flip between complete/name only listing of entries
  222. |
  223. (panel.size(false panel.size! false panel.attrs!
  224.             false panel.date! false panel.time!)
  225.        (true  panel.size! true  panel.attrs!
  226.         true  panel.date! true  panel.time!)
  227.        ifelse
  228. )wide_narrow!
  229. |
  230. (panel.rc drop linescols drop 2/ 1- <
  231.  (side_by_side)
  232.  (linescols drop 4/ nb_pn_lines! menu_line 1+ 0 panel.startrc!nb_pn_lines 79  panel.rc!
  233.   (nb_pn_lines menu_line 1++ 0 panel.startrc!nb_pn_lines 79  panel.rc!)in_next_panel
  234.  )
  235.  ifelse
  236. )top_bottom!
  237. |
  238. (linescols drop 2/ 1- nb_pn_lines! 0 startcol!
  239.  (nb_pn_lines 40  panel.rc! menu_line 1+ startcol panel.startrc! true panel.on!
  240.   normal_att current_att selected_att current_selected_att panel.att!
  241.   startcol 40+startcol!
  242.  )
  243.  loop_panels
  244. )side_by_side!
  245. |
  246. | the next code execute the action <top> for each panel
  247. |
  248. ("panel.on_activate"@oa! ()panel.on_activate! 
  249.   0 cnt! 
  250.   (cnt nb_panels <)
  251.   (cnt 1+ cnt! dup # next_panel)
  252.   while 
  253.   drop
  254.   oa "panel.on_activate!"&#
  255. )loop_panels!
  256. |
  257. |    switches panels on/off
  258. |    adapt the following code if you get rid of some of the panels or menus
  259. |
  260. (panel.on
  261.  ((false panel.on!)loop_panels main_menu_no window.uninstall
  262.   drive_menu_no window.uninstall)
  263.  ((true  panel.on!)loop_panels show_menu drive_menu)
  264.  ifelse
  265. )hide_all!
  266. |
  267. | swap the panels
  268. |
  269. (panel.startrc (panel.startrc 4 roll 4 roll panel.startrc!)in_next_panel
  270.  panel.startrc!)swap_panels!
  271. |
  272. |
  273. | Up/Down: move up/down; note that they do prevcmd/nextcmd if panels are off
  274. |
  275. (panel.on(current.pos 0=(beep)(current.pos 1 - current.pos!)ifelse)
  276.          (prevcmd)
  277.      ifelse
  278. )Up_panel!
  279. |
  280. (panel.on(current.pos panel.nbfiles 1- =(beep)(current.pos 1 + current.pos!)
  281.           ifelse)
  282.          (nextcmd)
  283.      ifelse
  284. )Down_panel!
  285. |
  286. |  go up/down one panel-windowfull
  287. |
  288. (current.pos panel.rc drop 2 - - current.pos!)PageUp_panel!
  289. (panel.rc drop 2 - current.pos + current.pos!)PageDown_panel!
  290. |
  291. | goto next/previous panel
  292. |
  293. (panel_directory cwd!)panel.on_activate!
  294. (cur_pn 1 + dup nb_panels>(nb_panels -)if dup cur_pn! window.activate)
  295. next_panel!
  296. (cur_pn 1 - dup 0 le(nb_panels +)if dup cur_pn! window.activate)
  297. prev_panel!
  298. |
  299. ( panel.type
  300.   (panel.pattern panel.type cutfirst drop panel.type&)
  301.   (panel.pattern)
  302.   ifelse
  303.   directory
  304. )panel_directory!
  305. |
  306. | Expand/Trim current panel
  307. |
  308. (panel.rc swap 3+ swap panel.rc!)expand_panel!
  309. (panel.rc swap 2- swap panel.rc!)trim_panel!
  310. |
  311. | search first file whose beginning matches contents of command line
  312. |
  313. (cmd cmd.clear file_to_search! find_again)find_file!
  314. (file_to_search "*.*"&dup next drop search current.name match(beep)ifnot)find_again!
  315. |
  316. | Replace selection pattern of current.name panel from command line contents
  317. |
  318. (cmd () ("*.*" cmd!) ifelse
  319. panel.pattern dirpart cmd&cmd.clear panel.pattern!)filter_files!
  320. |
  321. |  select all files matching command line contents; if the command
  322. | line is empty, select all.
  323. |
  324. (cmd cmd.clear dup(drop "*.*")ifnot
  325.  (dup current.name match(true current.selected!)if)loop_panel
  326.  drop
  327. )sel_match!
  328. |
  329. |  deselect all selected files matching pattern
  330. |
  331. (cmd cmd.clear dup(drop "*.*")ifnot
  332.  (dup current.name match(false current.selected!)if)loop_panel
  333.  drop
  334. )desel_match!
  335. |
  336. |  select/deselect current entry
  337. |
  338. (current.selected not current.selected!)select_on_off!
  339. |
  340. |  go up one level in directory hierarchy
  341. |
  342. (".."cwd! refresh)go_up!
  343. |
  344. ("go_up"panel.type&#)up_one_level!
  345. |
  346. |  go home
  347. |
  348. (0 current.pos!)go_home!
  349. |
  350. |  go to end of list of entries
  351. |
  352. (panel.nbfiles current.pos!)go_end!
  353. |
  354. |
  355. |              ┌─────────────────────────────┐
  356. |              │ actions on the command line │
  357. |              └─────────────────────────────┘
  358. |
  359. | prevcmd/nextcmd: replace command line with previous/next item in circular
  360. | list of saved commands.
  361. |
  362. | first, the variable nl is set to a newline.
  363. "
  364. "nl!
  365. |
  366. (cmdlist nl cutfirst swap drop nl cutfirst nl swap & swap dup the_cmd!
  367.  swap nl&swap&cmdlist! cmd.clear the_cmd cmd!)nextcmd!
  368. |
  369. (cmdlist nl cutlast dup the_cmd! nl swap&swap&cmdlist!cmd.clear the_cmd cmd!)
  370. prevcmd!
  371. |
  372. |  show the command stack.
  373. |
  374. (tmp!"tmp"@)quote!
  375. (
  376. cmdlist temp!""cmd2!temp nl cutfirst swap drop temp!
  377. (temp nl cutfirst swap dup)
  378. (dup "%"swap&"%"&nl&cmd2 swap&cmd2!
  379.  quote"("swap&"cmd!)"&#swap
  380.  temp!
  381. )while
  382. drop drop
  383. " Command Stack
  384. " cmd2&
  385. () "-1" "-1" temp_bordered_menu)view_cmdlist!
  386. |
  387. |  write 'current' to the command line
  388. |
  389. (current.name " "&cmd!)write_current!
  390. |
  391. | write the selected list to the command line
  392. |
  393. (selected_list deselect cmd!)write_all_selected!
  394. |
  395. |  write complete pathname of 'current' of next panel to the command line
  396. |
  397. ((panel.pattern dirpart current.name&" "&cmd!)in_next_panel)write_other_current!
  398. |
  399. |  add in turn to the command line the basename of each selected file
  400. |       and execute the resulting command
  401. |
  402. (cmd CMD!(CMD " "& swap &execshow)foreachbase)run_on_selected!
  403. |
  404. |  execute as an MSH script instruction the contents of the command line
  405. |
  406. (cmd cmd.clear#)exec_msh!
  407. |
  408. |  display on the command line, ready to be edited, the definition of
  409. | the identifier whose name was on the command line
  410. |
  411. (cmd @cmd&"!"&cmd.clear cmd!)definition!
  412. |
  413. | toggle insert mode
  414. |
  415. (cmd.imode(false cmd.imode!)(true cmd.imode!)ifelse)insert_toggle!
  416. |
  417. |
  418. |              ┌───────────────┐
  419. |              │ Miscellaneous │
  420. |              └───────────────┘
  421. |
  422. |
  423. | the next instruction defines the name of the config file
  424. |
  425. (prog_dir"config.msh"&)cfg_filename!
  426. |
  427. (0 0 linescols page_att page_status_att page_empty_att page_tab_att page)pager!
  428. |
  429. |
  430. ( "stats"
  431.   0 (current.size +)loop_panel
  432.   panel.nbfiles " files"&nl&
  433.   "total size "&" bytes "&swap &
  434.   message
  435. )panel_stats!
  436. |
  437. (3000 i!(0 i=not)(i 1-i!)while)test!
  438. |
  439. (dup 32 / dup 32 * 3 roll swap - " "&swap
  440.  dup 64 / dup 64 * 3 roll swap - dup 10 < ("0"swap&)if":"& 3 roll&swap
  441.  dup 32 / dup 32 * 3 roll swap - dup 10 < (" "swap&)if":"& 3 roll&swap
  442.  dup 32 / dup 32 * 3 roll swap - dup 10 < (" "swap&)if"/"&swap
  443.  dup 16 / dup 16 * 3 roll swap - dup 10 < ("0"swap&)if"/"&swap 80 +&&&
  444. )time_convert!
  445. |
  446. | The next code rereads the config file; this allows you to see the effect
  447. | of any changes you make in it|
  448. |
  449. ("config.msh" loaddefs)reconfig!
  450. |
  451. ("ascii table" prog_dir"ascii" makename read message)ascii!
  452. |
  453. ("do you want the captured screen to keep video attributes
  454.   as ANSI escapes (or a plain text file)" ok
  455.   "Please input the filename where the captured screen will be appended
  456.   (default is file 'screen' in MSH program directory)" 60 input dup 
  457.   (drop prog_dir"screen" makename)ifnot
  458.  swap capture_screen swap write refresh)capt_screen!
  459. |
  460. ("stats" current.name": "¤t.size&" bytes -- last modified "¤t.time
  461.  time_convert & message)file_stats!
  462. |
  463. (editor selected_list deselect &exec)edit_selected!
  464. |
  465. |
  466. | flip on/off Debug switch
  467. |
  468. (debug not debug!)debug_toggle!
  469. |
  470. ((stack_size 0 > ) (drop) while)clean_stack!
  471. |
  472. ( "time_menu_no"isdefined(time_menu_no window.uninstall)if
  473.   time time_convert ":" cutlast drop () menu_line 0=(73)(75)ifelse menu_line
  474.   permanent_menu time_menu_no!)show_clock!
  475. ( show_clock 1000 (clock)timer)clock!
  476. |
  477. | the following extend conveniently the dos commands
  478. |
  479. ("copy"panel.type&"to"&(panel.type)in_next_panel&#)copy_files!
  480. ("move"panel.type&"to"&(panel.type)in_next_panel&#)move_files!
  481. ("delete"panel.type&#)delete_files!
  482. ("browse"panel.type&#)browse_current!
  483. |
  484. (current.name pager)browse!
  485. |
  486. berk_cpmvrm(
  487. ("delete "selected_list& ok
  488.  ((dup current.isdir 
  489.        ("rd "swap&(execshow)with_nomagic)
  490.        (dup 100 swap"Deleting..." swap flash unlink)
  491.        ifelse
  492.   )foreachselected reread
  493.  )
  494.  if)delete!
  495. |
  496. ("copy "selected_list&" to "&next_dir& ok
  497.  (("copy "swap&" "&next_dir&(execshow)with_nomagic)foreachselected reread_next)
  498. if)copyto!
  499. |
  500. (panel.pattern directory next_dir=
  501.  ("warning" "cannot move files: next panel is the same directory" message)
  502.  ("move "selected_list&" to "&next_dir& ok
  503.   ((dup "copy "swap&" "&next_dir&(execshow)with_nomagic
  504.     dup 600 swap"Deleting..." swap flash unlink)
  505.    foreachselected reread reread_next
  506.   )if
  507.  )ifelse
  508. )moveto!
  509. )ifnot
  510. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  511.